package com.example.demowithdb.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.*;

@Controller
public class loginController {

    @GetMapping("/login")
    String loginForm() {
        return "login";
    }

    @PostMapping("/login")
    String submit(@RequestParam("username") String username,
                  @RequestParam("password") String password, HttpServletRequest request) {
        HttpSession session = request.getSession();
        if(!username.isEmpty()){
            session.setAttribute("user", username);
            return "success";
        }else{
            return "failure";
        }
    }
}